// pages/load/load.js
var app = getApp()
Page({

  data: {
    _shop_name: '',
    latitude: '',
    longitude: '',
    indicatorDots: true,
    autoplay: true,
    interval: 5000,
    duration: 1000,
    bannerimgs: ['/pages/images/banner.jpg'],
    list: [],
  },

  toMoreShops: function () {
    var lot = wx.getStorageSync('location').longitude
    var lat = wx.getStorageSync('location').latitude
    wx.navigateTo({
      url: '../more/index?lot=' + lot + "&lat=" + lat,
    })
  },
  onLoad: function (options) {
    var that = this
    if (options != undefined) {
      var shopId = decodeURI(options.shopId)
      if (shopId.length > 35) {
        app.globalData.category_id = shopId
        app.globalData.shopids = shopId
        wx.switchTab({
          url: '../index/index'
        })
      }
    }
    that.setData({
      url: app.globalData._new_url
    })
    wx.getLocation({
      success: function (res) {
        wx.setStorageSync('location', res)
        wx.showLoading({
          title: '数据加载中',
          mask: true
        })
        wx.showNavigationBarLoading()
        wx.request({
          url: app.globalData._new_url + 'MenuAPI/Shop/GetList',
          data: { currentJingdu: res.longitude, currentWeidu: res.latitude },
          method: 'post',
          success: function (res) {
            console.log(res)
            wx.hideLoading()
            wx.hideNavigationBarLoading()
            // console.log("商铺列表", res)
            if (res.data.status == 1) {
              var array = new Array
              for (var i = 0; i < res.data.value.length; i++) {
                if (i < 8) {
                  array.push(res.data.value[i]);
                }
              }
              console.log(array)
              that.setData({ _shop_list: array })
            } else {
              wx.showLoading({
                title: '获取商铺列表失败',
              })
            }
          }
        })
      },
    })
  },
  onShow: function () {
    this.onLoad()

  },
  toindex: function (e) {
    //isDiancanFlow:0便利店  ：1点餐
    var index = e.currentTarget.dataset.shopid
    var appid = e.currentTarget.dataset.appid
    var secret = e.currentTarget.dataset.secret
    var isDiancanFlow = e.currentTarget.dataset.deskopen
    var deskopen = e.currentTarget.dataset.deskopen == 0 ? false : true

    app.globalData.category_id = index
    app.globalData.shopids = index
    app.globalData.desk_open = deskopen
    wx.switchTab({
      url: '../index/index'
    })
  },

  onPullDownRefresh: function (e) {
    this.onLoad()
  },
  toyyminiapp: function () {
    wx.navigateToMiniProgram({
      appId: 'wxe695804e4a37ccb6',
      success: res => { console.log('ok') },
    })
  },
  togwminiapp: function () {
    wx.navigateToMiniProgram({
      appId: 'wx45a521c8bea73f83',
      success: res => { console.log('ok') },
    })
  }

})